﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class my_imginfo_edit : AdminpageBase
{
    protected int id = ReadRequest.RequestInt("id");
    protected string Titlestr = "";   
    protected Model.MembershipGrade model=null;
    protected string ctype =  ReadRequest.RequestString("t"); 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {    
            Model.MembershipGrade Info = BLL.MembershipGrade.GetModel(id);
            if (Info != null && Info.ID > 0)
            {
                titletxt.Text = Info.Title;
                moneytxt.Text = Info.Moeny.ToString();
                AllowFenxi.Checked = Info.AllowFenxi;
                AllowPinglun.Checked = Info.AllowPinglun;
                AllowYuce.Checked = Info.AllowYuCe;
                AllowZoushi.Checked = Info.AllowZoushi;
                AllowGoucai.Checked = Info.AllowGouCai;
            }
        }
    }
    protected void btn_submit_Click(object sender, EventArgs e)
    { 
        if (ctype.Equals("add"))
        {
            Titlestr = "添加";
            addinfo();
        }
        else if (ctype.Equals("edit"))
        {
            Titlestr = "更新";
            updateInfo(id);
        }
    }
    protected void updateInfo(int id)
    {
        Model.MembershipGrade Info = BLL.MembershipGrade.GetModel(id);
        if (Info != null && Info.ID > 0)
        {
            Info.Title = titletxt.Text;
            Info.Moeny = decimal.Parse(moneytxt.Text);
            Info.UpdateTime = DateTime.Now;
            Info.AllowFenxi = AllowFenxi.Checked;
            Info.AllowPinglun = AllowPinglun.Checked;
            Info.AllowYuCe = AllowYuce.Checked;
            Info.AllowZoushi = AllowZoushi.Checked;
            Info.AllowGouCai = AllowGoucai.Checked;
            BLL.MembershipGrade.Update(Info);
        }
        Response.Redirect("/manage/MembershipGrade/MembershipGrade.aspx");
    }
    protected void addinfo()
    {
        Model.MembershipGrade Info = new Model.MembershipGrade();
        Info.Title = titletxt.Text;
        Info.Moeny = decimal.Parse(moneytxt.Text);
        Info.Addtime = DateTime.Now;
        Info.UpdateTime = DateTime.Now;
        Info.AllowFenxi = AllowFenxi.Checked;
        Info.AllowPinglun = AllowPinglun.Checked;
        Info.AllowYuCe = AllowYuce.Checked;
        Info.AllowZoushi = AllowZoushi.Checked;
        Info.AllowGouCai = AllowGoucai.Checked;
        BLL.MembershipGrade.Add(Info);
        Response.Redirect("/manage/MembershipGrade/MembershipGrade.aspx");
    }
}